import request from "@/netword/request";


const fun = {};

// 分页查询所有信息
fun.getList = async (user) => {
    const res = await request({
        url: "/a/core/user/list",
        method: "post",
        params: {
            userNick: user.userNick,
            loginCode: user.loginCode,
            userPhone: user.userPhone,
            userEmail: user.userEmail,
            isSystem: user.isSystem,
            userGrade: user.userGrade,
            pageNo: user.pageNo,
            pageSize: user.pageSize,
            status: user.status
        }
    })
    return res.data;
}


// 不分页查询所有信息
fun.getListAll = async (user) => {
    const res = await request({
        url: "/a/core/user/listAll",
        method: "post",
        params: {
        }
    })
    return res.data;
}


//保存数据
fun.saveUser = async (user) => {
    const res = await request({
        url: "/a/core/user/save",
        method: "put",
        params: {
            loginCode: user.loginCode,
            password: user.password,
            userNick: user.userNick,
            userImage: user.userImage,
            userSex: user.userSex,
            userPhone: user.userPhone,
            userEmail: user.userEmail,
            isSystem: user.isSystem,
            userGrade: user.userGrade,
            remarks: user.remarks,
        }
    })
    return res.data;
}

//批量分配用户角色
fun.roleUser = async (userIds,roleCode) => {
    const res = await request({
        url: "/a/core/user/roleUser",
        method: "post",
        params: {
            userIds: userIds,
            roleCode: roleCode,
        }
    })
    return res.data;
}


//更新数据
fun.updateUser = async (user) => {
    const res = await request({
        url: "/a/core/user/update",
        method: "post",
        params: {
            id: user.id,
            loginCode: user.loginCode,
            password: user.password,
            userNick: user.userNick,
            userImage: user.userImage,
            userSex: user.userSex,
            userPhone: user.userPhone,
            userEmail: user.userEmail,
            isSystem: user.isSystem,
            userGrade: user.userGrade,
            remarks: user.remarks,
        }
    })
    return res.data;
}

//个人中心保存用户信息
fun.savePersonal = async (user) => {
    const res = await request({
        url: "/a/core/user/savePersonal",
        method: "post",
        params: {
            id: user.id,
            userNick: user.userNick,
            userImage: user.userImage,
            userSex: user.userSex,
            userPhone: user.userPhone,
            userEmail: user.userEmail,
            remarks: user.remarks,
        }
    })
    return res.data;
}


//个人中心用户修改密码
fun.saveUserPassword = async (id,originalPassword,newPassword) => {
    const res = await request({
        url: "/a/core/user/saveUserPassword",
        method: "post",
        params: {
            id: id,
            originalPassword: originalPassword,
            newPassword: newPassword,
        }
    })
    return res.data;
}

//重置密码
fun.initPwd = async (id) => {
    const res = await request({
        url: "/a/core/user/initPwd",
        method: "post",
        params: {
            id: id,
        }
    })
    return res.data;
}

//修改数据状态（正常，停用，删除）
fun.saveStatus = async (id, status) => {
    const res = await request({
        url: "/a/core/user/updateStatus",
        method: "post",
        params: {
            id: id,
            status: status
        }
    })
    return res.data;
}

//查询单条数据
fun.getUser = async (id) => {
    const res = await request({
        url: "/a/core/user/get",
        method: "get",
        params: {
            id: id
        }
    })
    return res.data;
}


export default fun;